package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Notice;
import cn.anxingongyou.anxin.mapper.NoticeMapper;
import cn.anxingongyou.anxin.service.NoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    private final NoticeMapper noticeMapper;
    @Autowired
    public NoticeServiceImpl(NoticeMapper noticeMapper) {
        this.noticeMapper = noticeMapper;
    }

    @Override
    public int insert(Notice notice) {
        return noticeMapper.insert(notice);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return noticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Notice notice) {
        return noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    public Notice selectOne(Notice notice) {
        return noticeMapper.selectOne(notice);
    }

    @Override
    public Notice selectOneByPrimaryKey(Long id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Notice> page(int pageNum, int pageSize, Notice notice) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<Notice> list = noticeMapper.select(notice);
        PageInfo<Notice> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
